﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Kaskelot.SP.Model.Contracts;
using Stockholm.SOA.Kaskelot.WCF.DataContracts;
using Kaskelot.SP.Core;
using Kaskelot.SP.Services;
using System.Linq;
using System.Collections.Generic;

namespace Kaskelot.SP.UI.CONTROLTEMPLATES.Kaskelot.SP.UI.Forms
{
	public partial class CreateValForm : BaseForm, IForm
	{
		public string Id { get; set; }
		public string ParentId { get; set; }
		public Val Current { get; set; }

		public string ValDatum
		{
			get
			{
				return Current.ValDatum.HasValue ? Current.ValDatum.Value.ToShortDateString() : String.Empty;
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			Current = new Val();

			using (AdminService svc = new AdminService())
			{
				IList<ListItem> list = new List<ListItem>();
				var v = svc.GetAllVal().OrderByDescending(x => x.ValDatum);

				foreach (Val val in v)
				{
					list.Add(new ListItem { Text = val.Namn, Value = val.Id.ToString() });
				}

				ValRepeater.DataSource = list;
				ValRepeater.DataBind();
			}
		}
	}
}
